<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="copyright" content=""/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>聚会+邀请函-分享设置</title>
    <link href="<%=path%>/favicon.ico" rel="shortcut icon">
    
    <link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
	<link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
	<link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">  
    <style>
        .x_basics_list li span{
            width: 10%;
        }
    </style>
</head>
<body class="gray-bg">
   <div class="wrapper wrapper-content animated fadeInRight">
    <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
			     <div class="ibox">	
				    <div class="ibox-content text-right">
				      <h3>
						<span>
							<button  type="button" class="btn btn-primary" onclick="window.location.href='<%=path%>/api/bm/ui/createActivity1'">重新选择模板</button>
						</span>
					  </h3>
				    </div>
			     </div>   
			   </div> 
                <div hidden="" class="x_progress x_basics">
                    <!--步骤-->
                    <div class="progress">
                        <div class="progress-bar progress-bar-warning" role="progressbar"
                             aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
                            <span class="sr-only_1">1</span>
                            <p class="x_color_bz">选择模板</p>
                        </div>
                        <div class="progress-bar progress-bar-warning" role="progressbar"
                             aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
                            <span class="sr-only_1">2</span>
                            <p class="x_color_bz">编辑内容</p>
                        </div>
                        <div class="progress-bar progress-bar-warning" role="progressbar"
                             aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
                            <span class="sr-only_1">3</span>
                            <p class="x_color_bz x_color_dq" style="color:#ffc105;">分享设置</p>
                        </div>
                        <div class="progress-bar progress-bar-info" role="progressbar"
                             aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
                            <span class="sr-only_2">4</span>
                            <p class="x_color_bz">活动预览</p>
                        </div>
                        <div class="progress-bar progress-bar-info" role="progressbar"
                             aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
                            <span class="sr-only_2">√</span>
                            <p class="x_color_bz">分享</p>
                        </div>
                    </div>
                    <!--步骤end-->                   
                </div>
                <div class="col-md-12">
                  <div class="ibox">	
				    <div class="ibox-content text-right">
				      <form method="post" class="form-horizontal" id='share_pic_upload' enctype='multipart/form-data'>
	                      <div class="form-group">
	                         <label class="col-sm-1 control-label">活动名称</label>
	                         <div class="col-sm-6">
	                             <input id="title" type="text" class="form-control">
	                         </div>
	                      </div>
	                      <div class="form-group">
	                         <label class="col-sm-1 control-label">示例</label>
	                         <div class="col-sm-10 text-left">
	                             <img src="<%=path%>/images/marketing/aaa.png" />
	                         </div>
	                      </div>
	                       <div class="form-group">
	                         <label class="col-sm-1 control-label">标题</label>
	                         <div class="col-sm-6">
	                             <input id="share_title" type="text" class="form-control">
	                         </div>
	                      </div>
	                       <div class="form-group">
	                         <label class="col-sm-1 control-label">文案</label>
	                         <div class="col-sm-6">
	                             <input id="share_content" type="text" class="form-control">
	                         </div>
	                      </div>
	                       <div class="form-group">
	                         <label class="col-sm-1 control-label">图片</label>
	                         <div class="col-sm-10 text-left">
	                         <img style="width: 100px;height: 100px" id="share_pic" src="<%=path%>/images/marketing/img_p.png">
	                             <input accept="image/gif,image/jpeg,image/x-png" type="file" id="inputfile" onchange="uploadPic()" name="filepath" style=" filter:alpha(opacity=50); -moz-opacity:0.5; -khtml-opacity: 0.5; opacity: 0.0;margin-top:-100px; position:absolute; z-index:99;">
	                             
	                         </div>
	                      </div>
	                      <div class="form-group">
	                      <label class="col-sm-1 control-label"></label>
	                         <div class="checkbox i-checks col-sm-2 text-left">
                                  <label>
                                      <input type="checkbox" value=""> <i></i>允许收录模板库</label>
                             </div>
	                      </div>
	                      
	                      <div class="form-group">
	                      <label class="col-sm-1 control-label"></label>
	                       <div class="col-sm-10" style="margin-left:8px; margin-top:20px;">
                             <button id="x_button_l" type="button" class="btn btn btn-default col-md-1" onclick="window.location.href='javascript:back();'">取消</button>
                             <button id="x_button_y" type="button" class="btn  btn-warning col-md-1" style="margin-left:5px" onclick="window.location.href='javascript:save();'">暂存</button>
                             <button id="x_button_bm" type="button" class="btn  btn-primary col-md-1" style="margin-left:5px" onclick="window.location.href='javascript:preview();'">下一步</button>
                           </div> 
	                      </div>
	                   </form>
                       
				    
				    
                    </div>
			     </div>   
                </div>
            </div>
        </div>
    </div> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
   	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js"></script>

	<script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/content.min.js?v=1.0.0"></script>
    <script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
	
    <script>
        $('.J_x_box').click(function () {
        $('.x_popup').show();
        $('.issue').show();
    });
    $('.x_popup .issue span').click(function () {
        $('.x_popup').hide();
        $('.issue').hide();
    });
    $('.s_fx_li12').click(function () {
        var id = $(this).find('img').attr('_id');
        if (id == 23) {
            $('.s_fk_pic12').attr('src', '<%=path%>/images/marketing/s_check_no.png');
            $(this).find('img').attr('_id', '24');
        } else {
            $('.s_fk_pic12').attr('src', '<%=path%>/images/marketing/s_check.png');
            $(this).find('img').attr('_id', '23');
        }
    });
    
    $('.x_radio_li5').click(function () {
        var id = $(this).find('img').attr('_id');
        if (id == 9) {
            $('.x_radio_pic5').attr('src', '<%=path%>/images/marketing/img_radio_n.png');
            $(this).find('img').attr('_id', '10');
        } else {
            $('.x_radio_pic5').attr('src', '<%=path%>/images/marketing/img_radio.png');
            $(this).find('img').attr('_id', '9');
        }
    });
    $('.x_radio_li6').click(function () {
        var id = $(this).find('img').attr('_id');
        if (id == 11) {
            $('.x_radio_pic6').attr('src', '<%=path%>/images/marketing/img_radio_n.png');
            $(this).find('img').attr('_id', '12');
        } else {
            $('.x_radio_pic6').attr('src', '<%=path%>/images/marketing/img_radio.png');
            $(this).find('img').attr('_id', '11');
        }
    });
    
    
    $('.x_button_l k_btn_one').click(function(){
    	window.location.href = "<%=path%>/api/bm/ui/invitation01?type=activity&&activity_id="+activity_id;
    });
    function back(){
    	window.location.href = "<%=path%>/api/bm/ui/invitation01?type=edit&&activity_id="+activity_id;
    }
    
    
    
    var save_tag=false;
    var actiivty_id;
    
    var share_title;
    var activity_name;
    var tag;
    var share_content;
    var share_pic;
	var access_token=$.cookie('access_token');
	var cid=$.cookie('cid');
	var uid=$.cookie('uid');
	var preview_tag=false;
    $(function(){
    	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
    	
    	activity_id=getQueryString("activity_id");
    	console.log(activity_id);
    	if(StringEmpty(activity_id)){
    		getActivityInfo(activity_id);
    	}
    	sysBack();
    });
    
  //获取活动信息
	function getActivityInfo(activity_id) {
		var url="<%=path%>/activity/detail";
		$.post(url, {
			"access_token" : access_token,
			"cid" : cid,
			"uid" : uid,
			"activity_id" : activity_id,
		}, function(data) {
			
			if (data.status == 200&&data.data!=undefined) {
				
				setActivityInfo(data.data);
			} else {
				
			}
		});
	}
	function save(){
		activity_name=$("#title").val();
		share_title=$("#share_title").val();
		tag=$("#defined_tag").val();
		share_content=$("#share_content").val();
		
    	if(StringEmpty(share_title)&&!isNaN(share_title)){
    		showDialog("分享标题不能只输入数字");
    		return ;
    	}
    	if(StringEmpty(share_content)&&!isNaN(share_content)){
    		showDialog("分享内容不能只输入数字");
    		return ;
    	}
		
		if(StringEmpty(share_title)&&
				StringEmpty(share_content)&&
				share_content.length<51&&
				StringEmpty(share_pic)){
			      createShare();
		}else if(!StringEmpty(share_title)){
			showDialog("请输入分享标题");
		}else if(!StringEmpty(share_content)){
			showDialog("请输入文案内容");
		}else if(!StringEmpty(share_pic)){
			showDialog("请上传图片");
		}
		else if(tag.length>10){
			showDialog("标签内容长度不能朝服哦10个字符");
		}else if(share_content.length>50){
			showDialog("文案内容长度不能超过50个字符");
		}
	}
	function createShare(){
        	var url = "<%=path%>/activity/create_share";
			$.post(url, {
				"access_token" : access_token,
				"cid" : cid,
				"uid" : uid,
				"activity_id" : activity_id,
				"tag_defined" : tag,
				"share_title" : share_title,
				"share_content" : share_content,
				"share_pic" : share_pic,
				"status":1,
				"coupon_number" : "1000000",
			}, function(data) {
				
				if (data.status == 200) {
					if(preview_tag){
						window.location.href = "<%=path%>/api/bm/ui/invitation02?activity_id="+activity_id;
					}else{
						showDialog("保存成功");
					}
				} else {
					showDialog("保存失败");
				}
			});
		
	}
	//设置显示信息
    function setActivityInfo(data){
    	activity_name=data.name;
    	console.log(data.name);
    	tag=data.tag_defined;
    	share_title=data.title;
    	share_content=data.content;
    	share_pic=data.pic;
    	if(StringEmpty(activity_name))
    	   $("#title").val(activity_name);
    	if(StringEmpty(tag))
    	   $("#defined_tag").val(tag); 
    	if(StringEmpty(share_title))
    	   $("#share_content").val(share_content); 
    	if(StringEmpty(share_content))
    	   $("#share_title").val(share_title); 
    	if(StringEmpty(share_pic))
    		$("#share_pic").attr('src',share_pic); 
    }
	
	function preview(){
		preview_tag=true;
		save();
	}
    
	var flag=false;
	function uploadPic() {
        $("#share_pic_upload").submit(function () {  
        	if(flag){
        		return ;
        	}
        	flag=true;
            $("#share_pic_upload").ajaxSubmit({
                type: "post",
                url: "${pageContext.request.contextPath}/api/uploadfile/file",
                data:{"typename":"filepath"},
                success: function (data1) {
                	
                	share_pic=data1.realSavePath;
                	$("#share_pic").attr('src',share_pic);
                },
                error: function (msg) {
                    showDialog("文件上传失败");    
                }
            });
            return false;
        });
        flag=false;
        $("#share_pic_upload").submit();
	}
	
    //获取参数
	function getQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return unescape(r[2]);
		return null;
	}

	//判断字符串是否为空
	function StringEmpty(content) {
		if (content == undefined || content == "" || content == null) {
			return false;
		} else {
			return true;
		}
	}
	
	 function showDialog(title){
			$('#dialog_title').html('<img src="<%=path%>/images/marketing/s_tick.png"/>'+title+''); 
			$('.s_popup_delect2,.s_consum').show().delay(2000).fadeOut();
		}
	 
	 
	 function sysBack(){
	    	pushHistory();
	 		  window.addEventListener("popstate", function(e) {
	 			 window.location.href = "<%=path%>/api/bm/ui/invitation01?type=edit&&activity_id="+activity_id;
	 		  }, false);
	    }
	    //后退
	    function pushHistory() {
			  var state = {
			  title: "title",
			  url: "#"
			  };
			  window.history.pushState(state, "title", "#");
		}
    </script>
<script type="text/javascript" src="<%=path%>/js/exit.js"></script>
</body>
</html>